const path = require('path');
const nodeExternals = require('webpack-node-externals');

const requireContext = require('require-context')
const files = requireContext(path.join(__dirname, './src'), true, /\.js$/)
// console.log(files.resolve(files.keys()[0]),'hahahaha123132')
const entrys = {}
files.keys().forEach(key => {
  if (key === 'index.js' || key === 'export.js') return
  const path = files.resolve(key)
  const url = '.\\src\\' + key
  let arr = path.split('\\')
  const name = arr[arr.length - 1].replace(/(.*\/)*([^.]+).*/ig, "$2");
  entrys[name] = url
})
console.log(entrys)
module.exports = {
  mode: 'production',
  // entry:['./src/Modal/modal','./src/Input/input'],
  entry: entrys,
  output: {
    path: path.resolve(__dirname, './dist/com'),
    libraryTarget: 'commonjs2',
    filename: '[name].js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.cm\.styl$/,
        loader: 'style-loader!css-loader?modules&camelCase&localIdentName=[local]-[hash:base64:5]!stylus-loader'
      }
    ]
  },
  externals: [nodeExternals()]
};